package top.greatxiaozou.testAop;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class BuyAspectJ {
//    @Pointcut("execution(* top.greatxiaozou.testAop.IBuy.buy())")
//    public void point(){}
//
//    @Before("point()")
//    public void haha(){
//        System.out.println("买东西之前");
//    }
//
//    @After("point()")
//    public void heihei(){
//        System.out.println("付钱");
//    }
//
//    @Around("point()")
//    public void qifei(ProceedingJoinPoint pj) throws Throwable {
//        System.out.println("before around");
//        pj.proceed();
//        System.out.println("after around");
//    }
//
//    @AfterReturning("point()")
//    public void hahaha(){
//        System.out.println("付钱完了，出门了！");
//    }
    @Pointcut("execution(String top.greatxiaozou.testAop.IBuy.buy(double)) && bean(girl) && args(price)")
    public void gir(double price){}

    @Around("gir(price)")
    public String girlBuy(ProceedingJoinPoint pj,double price) throws Throwable {
        if (price>65){
            pj.proceed();
            System.out.println("购物超过65元，送一双袜子");
            return "衣服和袜子";
        }
        return "衣服";
    }
}
